// Copyright (C) 2010 Razvan Constantin <razvan.constantin@rconst.net>
//
// This file is part of FileBow.
//
// FileBow is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// FileBow is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with FileBow.  If not, see <http://www.gnu.org/licenses/>.

#include "common/strings.h"

#include <string>
#include <vector>

#include <gtest/gtest.h>

using namespace std;

TEST(StringTest, TestSplit) {
  vector<string> parts;
  Split("test1 test2 test3", ' ', &parts);
  ASSERT_EQ(3, parts.size());
  EXPECT_EQ("test1", parts[0]);
  EXPECT_EQ("test2", parts[1]);
  EXPECT_EQ("test3", parts[2]);
}

TEST(StringTest, TestSplitOne) {
  EXPECT_EQ(1, Split("", ' ').size());
  EXPECT_EQ(1, Split("test", ' ').size());
  EXPECT_EQ("", Split("", ' ').front());
  EXPECT_EQ("test", Split("test", ' ').front());
}

TEST(StringTest, TestJoin) {
  vector<string> parts;
  EXPECT_EQ("", Join(parts, ", "));
  parts.push_back("elem1");
  EXPECT_EQ("elem1", Join(parts, ", "));
  parts.push_back("elem2");
  EXPECT_EQ("elem1, elem2", Join(parts, ", "));
  parts.push_back("elem3");
  EXPECT_EQ("elem1, elem2, elem3", Join(parts, ", "));
  EXPECT_EQ("elem1elem2elem3", Join(parts, ""));
}

TEST(StringTest, TestStartsWith) {
  EXPECT_FALSE(StartsWith("", ""));
  EXPECT_FALSE(StartsWith("test", ""));
  EXPECT_TRUE(StartsWith("test", "t"));
  EXPECT_TRUE(StartsWith("test", "te"));
  EXPECT_TRUE(StartsWith("test", "tes"));
  EXPECT_TRUE(StartsWith("test", "test"));
  EXPECT_FALSE(StartsWith("test", "tests"));
}
